<?php 

class Connection {

	static private $instance;
	private $db_user;
	private $db_pass;
	private $db_name;
	private $db_server;
	  
   	private function __construct() {
   		$this->db_user = 'root';
   		$this->db_pass = '';
   		$this->db_name = 'modelweb';
   		$this->db_server = 'localhost';	
   	}
   	
    // The singleton method
    public static function singleton() 
    {
        if (!isset(self::$instance)) {
            $c = __CLASS__;
            self::$instance = new $c;
        }

        return self::$instance;
    }

	function transaction_begin(){
		try {
			$link =  mysql_connect($this->db_server, $this->db_user, $this->db_pass = '');
			if (!$link) 
				throw new Exception(CONNECTION_SERVER_ERROR);
			
			if (!mysql_select_db($this->db_name,$link))
					throw new Exception(CONNECTION_DB_ERROR);
			
			mysql_query("begin");
										
			return $link;
		}
		catch (Exception $e) {
			mysql_close($link);
			Exception_handler::singleton()->handler($e);
		}
	}
		
	function transaction_rollback($link){
		mysql_query("rollback");
		mysql_close($link);
	}
	
	function transaction_commit($link) { 
		mysql_query("commit");
		mysql_close($link);		
	}
	
}



	
?>